package com.infocollect.project.grant.controller;

import java.util.List;

import com.infocollect.project.system.service.ISysConfigService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.infocollect.framework.aspectj.lang.annotation.Log;
import com.infocollect.framework.aspectj.lang.enums.BusinessType;
import com.infocollect.project.grant.domain.GrScene;
import com.infocollect.project.grant.service.IGrSceneService;
import com.infocollect.framework.web.controller.BaseController;
import com.infocollect.framework.web.domain.AjaxResult;
import com.infocollect.common.utils.poi.ExcelUtil;
import com.infocollect.framework.web.page.TableDataInfo;

/**
 * 签到场次Controller
 * 
 * @author infocollect
 * @date 2022-05-14
 */
@RestController
@RequestMapping("/grant/scene")
public class GrSceneController extends BaseController
{
    @Autowired
    private IGrSceneService grSceneService;
    @Autowired
    private ISysConfigService configService;
    /**
     * 查询签到场次列表
     */
    @PreAuthorize("@ss.hasPermi('grant:scene:list')")
    @GetMapping("/list")
    public TableDataInfo list(GrScene grScene)
    {
        String enrollHost =  configService.selectConfigByKey("enroll_host");
        startPage();
        List<GrScene> list = grSceneService.selectGrSceneList(grScene);
        for(GrScene scene:list){
            scene.setEnrollHost(enrollHost);
        }
        return getDataTable(list);
    }

    /**
     * 导出签到场次列表
     */
    @PreAuthorize("@ss.hasPermi('grant:scene:export')")
    @Log(title = "签到场次", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GrScene grScene)
    {
        List<GrScene> list = grSceneService.selectGrSceneList(grScene);
        ExcelUtil<GrScene> util = new ExcelUtil<GrScene>(GrScene.class);
        return util.exportExcel(list, "scene");
    }

    /**
     * 获取签到场次详细信息
     */
    @PreAuthorize("@ss.hasPermi('grant:scene:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(grSceneService.selectGrSceneById(id));
    }

    /**
     * 新增签到场次
     */
    @PreAuthorize("@ss.hasPermi('grant:scene:add')")
    @Log(title = "签到场次", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrScene grScene)
    {
        return toAjax(grSceneService.insertGrScene(grScene));
    }

    /**
     * 修改签到场次
     */
    @PreAuthorize("@ss.hasPermi('grant:scene:edit')")
    @Log(title = "签到场次", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrScene grScene)
    {
        return toAjax(grSceneService.updateGrScene(grScene));
    }

    /**
     * 删除签到场次
     */
    @PreAuthorize("@ss.hasPermi('grant:scene:remove')")
    @Log(title = "签到场次", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(grSceneService.deleteGrSceneByIds(ids));
    }
}
